package com.pp.manage.service.impl;

import com.pp.manage.mapper.UserMapper;
import com.pp.manage.pojo.User;
import com.pp.manage.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author yangfan
 * @date 2020/7/14 12:09
 * @description
 */

@Service("userService")
public class UserService implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Transactional
    @Override
    public boolean insertUser(User user) {
        Date date = new Date();
        user.setState("1");
        user.setCreate_time(date);
        user.setUpdate_time(date);
        return userMapper.insertUser(user) == 1;
    }

    @Transactional
    @Override
    public boolean deleteUserTemporary(Integer userId) {
        return userMapper.deleteUserTemporary(userId) == 1;
    }

    @Transactional
    @Override
    public boolean deleteUser(Integer userId) {
        return userMapper.deleteUser(userId) == 1;
    }

    @Transactional
    @Override
    public boolean updateUser(User user) {
        user.setUpdate_time(new Date());
        return userMapper.updateUser(user);
    }

    @Override
    public User findUserById(Integer userId) {
        return userMapper.findUserById(userId);
    }

    @Override
    public List<User> findAllUser() {
        return userMapper.findAllUser();
    }
}
